package interview;

import javax.swing.tree.TreeNode;

public class interview_04_02 {
    class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(int x) { val = x; }
    }
    public TreeNode sortedArrayToBST(int[] nums) {
        int len=nums.length;
        return sortTree(nums,0,len-1);
    }
    public TreeNode sortTree(int[] nums,int left,int right){
        if(left>right) return null;
        int mid=left+(right-left)/2;
        TreeNode node=new TreeNode(nums[mid]);
        node.left=sortTree(nums,left,mid-1);
        node.right=sortTree(nums,mid+1,right);
        return node;
    }
}
